package com.qingzhu.dao.impl;

import com.qingzhu.dao.OrderDao;
import com.qingzhu.pojo.Order;
import com.qingzhu.util.CreateSqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OrderDaoImpl implements OrderDao {
    @Override
    public int insterOrder(Order order) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            int result = orderDao.insterOrder(order);
            return result;
        }
    }

    @Override
    public List<Order> findOrderAll(String status,int userId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            return orderDao.findOrderAll(status,userId);
        }
    }

    @Override
    public Order findOrderById(String searchInput,int userId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            return orderDao.findOrderById(searchInput,userId);
        }
    }

    @Override
    public int deleteOrderById(int orderId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            return orderDao.deleteOrderById(orderId);
        }
    }

    @Override
    public List<Order> findDelOrderAll(int userId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            return orderDao.findDelOrderAll(userId);
        }
    }

    @Override
    public int recoveryOrderById(int orderId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            return orderDao.recoveryOrderById(orderId);
        }
    }

    @Override
    public int findNoPayOrderNum(Integer userId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            return orderDao.findNoPayOrderNum(userId);
        }
    }

    @Override
    public int findNoRecGoodsOrderNum(Integer userId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            return orderDao.findNoRecGoodsOrderNum(userId);
        }
    }

    @Override
    public int findNoEvaluateOrderNum(Integer userId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
            return orderDao.findNoEvaluateOrderNum(userId);
        }
    }
}
